import java.io.*;
import java.nio.*;
import java.nio.channels.*;
import java.nio.charset.*;
import java.net.*;
import java.util.*;


/**
 * InputHandler
 * Threaded. Handles incoming input from a socket. Input is then placed in a drop.
 * @author James Varvaro
 */
public class InputHandler extends Thread {
    private Socket socket;
    private Drop drop;
    
    public InputHandler(Socket aSocket, Drop aDrop) {
        this.socket = aSocket;
        this.drop = aDrop;
    }
    
    public void run() {
        BufferedReader in = null;
        try {
            in = new BufferedReader(
                     new InputStreamReader(
                         socket.getInputStream()));
        }
        catch(IOException ex) {
            System.out.println("Couldn't initialize input handler.");
            System.exit(-1);
        }
        String inputLine = "";
        try {
            while((inputLine = in.readLine()) != null) {
                drop.put(inputLine);
            }
        }
        catch(IOException ex) {
            System.out.println("Couldn't receive input.");
            return;
        }
    }
}
